<script setup lang="ts">
import {onMounted} from "vue";
import {reqGetUserInfo} from "@/api/user";
import {useUserStore} from "@/store/user";

const userStore = useUserStore()

function extracted(url: String) {
  userStore.logout()
  setTimeout(() => {
    uni.reLaunch({
      url: url
    })
  }, 1500)
}

onMounted(async () => {
  if (userStore.token) {
    await reqGetUserInfo(userStore.token).then(res => {
      if (res.code == 200) {
        userStore.userInfo = {...res.data}
        setTimeout(() => {
          uni.switchTab({
            url: '/pages/home/home'
          })
        }, 1500)
      } else {
        extracted("/pages/login/login");
      }
    }).catch(err => {
      extracted("/pages/login/login");
    })
  } else {
    extracted("/pages/login/login");
  }

})
</script>

<template>
  <view class="container">
    <image class="back" src="/static/images/index/Group.png"/>
    <view class="logo">
      <image src="/static/images/index/cur-asm@3x.png"/>
      <text>书香阁</text>
    </view>
    <image class="loading" src="/static/images/index/Frame.png"/>
  </view>
</template>

<style lang="scss" scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;

  .back {
    position: absolute;
    top: 402rpx;
    width: 693.04rpx;
    height: 668rpx;
  }

  .loading {
    position: absolute;
    bottom: 100rpx;
    width: 80rpx;
    height: 80rpx;
  }

  .logo {
    display: flex;
    top: 700rpx;
    position: absolute;
    align-items: center;

    image {
      width: 100rpx;
      height: 100rpx;
      border-radius: 25rpx;
    }

    text {
      margin-left: 30rpx;
      font-size: 40rpx;
      font-weight: bold;
    }
  }

}
</style>
